feat(error-tracking): PostHog autocapture + sourcemap upload#21
Merged
Conversation
…on, source-map upload Greenfield PostHog wiring (the repo had none). Errors-only scope — no analytics-event capture, no opt-in UI (PostHog error tracking is treated as technical telemetry, not user tracking). - `src/lib/analytics.ts` (NEW): array.js shim loader gated on `IS_PRODUCTION && POSTHOG_KEY`; init passes `capture_exceptions: true`; exports a `captureException(error, properties?)` wrapper. - `src/lib/config.ts`: add `posthogKey` / `posthogHost` to the `DashboardConfig` interface + matching const exports. - `src/app.ts`: call `initAnalytics()` before bootstrap so the SDK loads in parallel with the WS connection. - `src/server.ts`: CSP extends `script-src` with `https://us-assets.i.posthog.com` and the production `connect-src` with `https://us.i.posthog.com`. Map blocker already in place. - `src/build.ts`: flip `sourcemap` always-on for production builds. - `deploy.yml` (testnet + mainnet): add `POSTHOG_KEY` env from `secrets.POSTHOG_PROJECT_TOKEN`, validate non-empty, inject `posthogKey` + `posthogHost` into the generated `config.js`. After build, run `posthog-cli sourcemap inject` + `... upload` and add `--exclude "*.map"` to the `aws s3 sync` so maps stay off Tigris. PostHog CLI env: `POSTHOG_CLI_API_KEY` from secrets, `POSTHOG_CLI_PROJECT_ID=345524`, `POSTHOG_CLI_HOST=https://us.posthog.com`. Init config uses `capture_exceptions: true` (posthog-js v1.376+ renamed from `autocapture_exceptions`). Verified locally with a production build + posthog-cli upload against the real personal API key.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Greenfield PostHog wiring (repo had no analytics module). Errors-only scope — no analytics-event capture, no opt-in UI (PostHog error tracking is treated as technical telemetry, not user tracking).
src/lib/analytics.ts(NEW): array.js shim loader gated onIS_PRODUCTION && POSTHOG_KEY. ExportsinitAnalytics()+captureException(error, properties?).src/lib/config.ts: addposthogKey/posthogHosttoDashboardConfig+ matching const exports.src/app.ts:initAnalytics()before bootstrap.src/server.ts: CSP extendsscript-srcwithhttps://us-assets.i.posthog.comand the productionconnect-srcwithhttps://us.i.posthog.com. The repo's existing.map404 blocker is unchanged.src/build.ts: flipsourcemapalways-on for production builds.deploy.yml(testnet + mainnet): addPOSTHOG_KEYenv fromsecrets.POSTHOG_PROJECT_TOKEN, validate non-empty, writeposthogKey+posthogHostinto the generatedconfig.js. After build,posthog-cli sourcemap inject + upload.aws s3 syncgains--exclude "*.map"so maps stay off Tigris.Implements part of ClickUp task
86c8x4a3p"Add PostHog error tracking to all UI apps" (1 of 5 frontends — see also provider-console, council-console, moonlight-pay, browser-wallet).Test plan
deno task checkcleandeno task lintcleandeno task fmt:checkcleandeno task test— 13 passeddeno task build -- --productionemitspublic/app.js(32 KB) +public/app.js.map(126 KB)posthog-cli sourcemap inject + upload --directory public/succeeded locally; PostHog releasenetwork-dashboard@1edb565611db9c0d28f70779d79449ebff32b42acreatedENVIRONMENT=production deno task serveon :3030 with a real project token inpublic/config.js, errors land in PostHog Errors dashboard with.ts-resolved stack framesUpload source maps to PostHogstep successfullyCaveats
capture_exceptions: true(posthog-js v1.376+ renamed it fromautocapture_exceptions). PostHog's older docs still reference the old name;capture_exceptionsis the field actually read by the SDK.POSTHOG_PROJECT_TOKENandPOSTHOG_CLI_API_KEYto this repo as GH secrets.